﻿/*
Commerce by Onex – eCommerce software platform (www.ecommerce.byonex.com)
Copyright (C) 2008-2010 by Onex Group

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 */
using System;
using System.Collections.Generic;
using System.Text;

namespace ShopModel
{
    #region Enums

    public enum PropertyType
    {
        Text = 1,
        Dictionary = 2,
        Numeric = 3,
        MultiDictionary = 4,
    }

    #endregion Enums


    /// <summary>
    /// Klasa opisująca właściwość produktu.
    /// (Class describing a property of the product.)
    /// </summary>
    /// <remarks>
    /// Autor: Paweł Janiszewski
    /// Data: 19.06.2008
    /// </remarks>
    [Serializable]
    public class ProductProperty
    {
        #region Variables

        protected int id;
        protected string propertyValue;
        protected string name;
        protected string label;
        //protected bool isDictionaryType;
        protected string description;
        protected bool isNew;
        protected bool isSearchCriterion;
        protected PropertyType propertyType;
        protected decimal? propertyNumericValue;
        protected decimal? propertyNumericValueFrom;
        protected decimal? propertyNumericValueTo;

        #endregion Variables

        #region Constructors

        public ProductProperty()
        {
            this.id = -1;
            this.propertyValue = string.Empty;
            this.name = string.Empty;
            this.label = string.Empty;
            this.propertyType = PropertyType.Text;
            this.description = string.Empty;
            this.isNew = false;
            this.isSearchCriterion = true;
            this.propertyNumericValue = null;
            this.propertyNumericValueFrom = null;
            this.propertyNumericValueTo = null;

        }

        #endregion Constructors

        #region Fields

        /// <summary>
        /// Id właściwości
        /// </summary>
        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        /// <summary>
        /// Wartośc właściwości
        /// </summary>
        public string Value
        {
            get { return propertyValue; }
            set { propertyValue = value; }
        }

        public decimal? NumericValue
        {
            get
            {

                if (propertyNumericValue.HasValue)
                {
                    if (propertyNumericValue.Value.ToString().Contains(".") || propertyNumericValue.Value.ToString().Contains(","))
                    {
                        return Convert.ToDecimal(propertyNumericValue.Value.ToString().TrimEnd('0').TrimEnd('.').TrimEnd(','));
                    }
                    else
                        return propertyNumericValue.Value;

                }
                else
                    return null;

            }
            set { propertyNumericValue = value; }
        }

        public decimal? NumericValueFrom
        {
            get { return propertyNumericValueFrom; }
            set { propertyNumericValueFrom = value; }
        }

        public decimal? NumericValueTo
        {
            get { return propertyNumericValueTo; }
            set { propertyNumericValueTo = value; }
        }

        /// <summary>
        /// Nazwa właściwości
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public PropertyType TypeOfProperty
        {
            get { return propertyType; }
            set { propertyType = value; }
        }

        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        public bool IsNew
        {
            get { return isNew; }
            set { isNew = value; }
        }

        public bool IsSearchCriterion
        {
            get { return isSearchCriterion; }
            set { isSearchCriterion = value; }
        }

        #endregion Fields
    }
}
